home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / varia / egebook.lha / ege.book / 5 / String.h < prev    next >
C/C++ Source or Header  |  1992-06-05  |  1KB  |  55 lines

  1. #ifndef _String
  2. #define _String
  3.  
  4. #include <iostream.h>
  5. #include <string.h>
  6. #include "bool.h"
  7.  
  8. class String {
  9.      char *str ;
  10.      static const int MaxLength;
  11.    public:
  12.      String(const char *s = "") {
  13.        str = new char[strlen(s) + 1];
  14.        strcpy(str,s);
  15.      }
  16.      String(const String &s) {
  17.        str = new char[strlen(s.str) + 1];
  18.        strcpy(str,s.str);
  19.      }
  20.      String& operator=(const String& s) {
  21.        if (&s != this) {
  22.      delete [] str;
  23.      str = new char[strlen(s.str) + 1];
  24.      strcpy(str,s.str);
  25.        }
  26.        return *this;
  27.      }
  28.      String& operator+(const String& s) {
  29.        char *tmp = new char [strlen(str) + strlen(s.str) +1];
  30.        strcpy(tmp,str);
  31.        strcat(tmp,s.str);
  32.        return *new String(tmp);
  33.      }
  34.      void print() {
  35.        cout << str;
  36.      }
  37.      int operator==(const String& s) {
  38.        return !strcmp(str,s.str);
  39.      }
  40.      bool contains(String);
  41. //     operator char*() {
  42. //       return str;
  43. //     }
  44.      friend istream& operator>>(istream&, String&);
  45.      friend ostream& operator<<(ostream&, String&);
  46.      ~String(){
  47.        delete [] str;
  48.      }
  49. } ;
  50.  
  51. #endif
  52.  
  53.  
  54.  
  55.